var e = require;
var t = module;
var o = exports;
var n;
function i(e, t) {
    return (i =
        Object.setPrototypeOf ||
        function (e, t) {
            return (e.__proto__ = t), e;
        })(e, t);
}
(o.__esModule = !0), (o.default = void 0);
var a = (function (e) {
    var t, o;
    function n() {
        var t;
        return ((t = e.call(this) || this).yuanshengIndex = 0), (t.yuanshengADK = null), t;
    }
    (o = e), ((t = n).prototype = Object.create(o.prototype)), (t.prototype.constructor = t), i(t, o);
    var a = n.prototype;
    return (
        (a.init = function () {
            (this.env = window.qg),
                (this.info = (window.lplatform && lplatform.systemInfo) || this.env.getSystemInfoSync()),
                (this.bh = lplatform.cparam.bannerHeight || 170),
                (this.bw = lplatform.cparam.bannerWidth || Math.min(this.info.windowWidth, (16 * this.bh) / 9)),
                "function" == typeof this.env.getGameRecorder &&
                    (this.gameRecorderManager = this.env.getGameRecorder()),
                this.env.setKeepScreenOn &&
                    this.env.setKeepScreenOn({
                        keepScreenOn: !0,
                        success: function success() {
                            console.log("handling success");
                        },
                        fail: function fail(e, t) {
                            console.log("handling fail, code = " + t);
                        }
                    });
        }),
        (a.initAD = function () {
            this.loadBanner(!1), this.createRewardedVideo(!1), this.loadMoreGamePortal(!1);
        }),
        (a.createRewardedVideo = function (e) {
            lplatform.cparam.rewardedVideoID &&
                (this.rewardedVideoAd ||
                    "function" != typeof this.env.createRewardedVideoAd ||
                    ((this.rewardedVideoAd = this.env.createRewardedVideoAd({
                        adUnitId: lplatform.cparam.rewardedVideoID
                    })),
                    this.rewardedVideoAd.onError(this.onRewardedVideoError.bind(this)),
                    this.rewardedVideoAd.onClose(this.onRewardedVideoClose.bind(this)),
                    this.rewardedVideoAd.onLoad(this.onRewardedVideoLoad.bind(this))),
                e && this.showRewardedVideo(window.vcb));
        }),
        (a.showRewardedVideo = function (e) {
            var t = this;
            e && (window.vcb = e),
                this.rewardedVideoAd
                    ? (lplatform.plog("showRewardedVideo this.rewardedVideoIsLoaded:" + this.rewardedVideoIsLoaded),
                      this.rewardedVideoAd
                          .show()
                          .then(function () {
                              lplatform.plog("oppo的rewardedVideo.show().then()在视频结束时才调用，shit.");
                          })
                          .catch(function (e) {
                              lplatform.plog("showRewardedVideo catch:" + JSON.stringify(e)),
                                  t.rewardedVideoAd
                                      .load()
                                      .then(function () {
                                          t.rewardedVideoAd.show();
                                      })
                                      .catch(function () {
                                          t.loadRewardedVideo(!1);
                                      });
                          }))
                    : this.createRewardedVideo(!0);
        }),
        (a.onRewardedVideoError = function (t, o) {
            e.prototype.onRewardedVideoError.call(this, t, o),
                this.env.showToast({title: "加载中，请稍候", message: "加载中，请稍候"});
        }),
        (a.onRewardedVideoClose = function (t) {
            e.prototype.onRewardedVideoClose.call(this, t);
        }),
        (a.showFavoriteGuide = function () {
            var e = this;
            e.env.hasShortcutInstalled({
                success: function success(t) {
                    0 == t &&
                        e.env.installShortcut({
                            success: function success() {},
                            fail: function fail() {},
                            complete: function complete() {}
                        });
                },
                fail: function fail() {},
                complete: function complete() {}
            });
        }),
        (a.createMoreGamePortal = function (e, t) {
            var o = this;
            void 0 === e && (e = !1),
                void 0 === t && (t = !1),
                console.log("poppo createMoreGamePortal"),
                this.moreGamePortal
                    ? (console.log("直接显示", JSON.stringify(this.moreGamePortal)),
                      this.moreGamePortal
                          .show()
                          .then(function () {
                              console.log("show success");
                          })
                          .catch(function (e) {
                              console.log("show fail with:" + e.errCode + "," + e.errMsg),
                                  window.moreGameButton && (window.moreGameButton.active = !1),
                                  o.moreGamePortal.destroy(),
                                  o.loadMoreGamePortal(!0);
                          }))
                    : (console.log("加载后直接显示"), this.loadMoreGamePortal(!0));
        }),
        (a.loadMoreGamePortal = function (e) {
            var t = this;
            this.moreGamePortal && (this.moreGamePortal.destroy(), (this.moreGamePortal = null)),
                (this.moreGamePortal = qg.createGamePortalAd({adUnitId: lplatform.cparam.spreadBoxID[0]})),
                this.moreGamePortal.onLoad(function () {
                    console.log("互推盒子九宫格广告加载成功"),
                        window.moreGameButton && (window.moreGameButton.active = !0),
                        e &&
                            t.moreGamePortal
                                .show()
                                .then(function () {
                                    console.log("show success");
                                })
                                .catch(function (e) {
                                    console.log("show fail with:" + e.errCode + "," + e.errMsg),
                                        window.moreGameButton && (window.moreGameButton.active = !1);
                                });
                }),
                this.moreGamePortal.onClose(function () {
                    console.log("互推盒子九宫格广告关闭"),
                        t.moreGamePortal
                            .destroy()
                            .then(function () {
                                console.log("destroy success");
                            })
                            .catch(function (e) {
                                console.log("destroy fail with:" + e.errCode + "," + e.errMsg);
                            }),
                        t.loadMoreGamePortal(!1);
                }),
                this.moreGamePortal.onError(function (e) {
                    window.moreGameButton && (window.moreGameButton.active = !1),
                        console.log("互推盒子九宫格加载失败" + JSON.stringify(e));
                });
        }),
        (a.createMoreGameButton = function () {}),
        (a.createMoreGameBanner = function () {
            if (lplatform.cparam.moreGameBannerId) {
                if (!this.moreGameBanner) {
                    lplatform.cparam.moreGameBannerWidth;
                    var e = lplatform.cparam.moreGameBannerHeight;
                    (this.btop = 0),
                        lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - e),
                        (this.moreGameBanner = this.env.createGameBannerAd({
                            adUnitId: lplatform.cparam.moreGameBannerId
                        })),
                        this.moreGameBanner.onError(function (e, t) {
                            lplatform.plog("监听事件:" + JSON.stringify(e) + " " + JSON.stringify(t));
                        });
                }
                this.moreGameBanner.show(),
                    lplatform.cparam.moreGameBannerAutoCloseTime > 0 &&
                        setTimeout(
                            function () {
                                this.moreGameBanner.hide();
                            }.bind(this),
                            lplatform.cparam.moreGameBannerAutoCloseTime
                        );
            }
        }),
        (a.showShareMenu = function () {}),
        (a.shareAppMessage = function () {}),
        (a.canRecord = function () {
            return !(!this.gameRecorderManager || !lplatform.cparam.canRecord);
        }),
        (a.canShareRecord = function () {
            return !1;
        }),
        (a.startRecord = function () {}),
        (a.onGameRecordStart = function () {}),
        (a.onGameRecordError = function () {}),
        (a.pauseRecord = function () {}),
        (a.resumeRecord = function () {}),
        (a.stopRecord = function () {}),
        (a.resetRecord = function () {}),
        (a.shareInnerRecord = function () {}),
        (a.showBanner = function () {
            e.prototype.showBanner.call(this);
        }),
        (a.loadInterstitial = function () {
            var e = this;
            lplatform.plog("createNativeAd lplatform.cparam.nativeID:" + lplatform.cparam.nativeID);
            var t = lplatform.cparam.nativeID;
            (this.yuanshengIndex += 1),
                this.yuanshengIndex >= t.length && (this.yuanshengIndex = 0),
                e.nativeAd && (e.nativeAd.destroy(), (e.nativeAd = null));
            var o = qg.createNativeAd({adUnitId: t[this.yuanshengIndex]});
            (e.nativeAd = o),
                o.onLoad(
                    function (t) {
                        lplatform.plog("nativeAd.onLoad:" + JSON.stringify(t)),
                            o.reportAdShow({adId: t.adList[0].adId}),
                            e.yuanshengADK &&
                                e.yuanshengADK.destroy &&
                                (lplatform.plog("onLoad this.yuanshengADK.destroy:" + e.yuanshengADK.destroy),
                                e.yuanshengADK.destroy()),
                            lplatform.labData.mainSwitch &&
                                (e.yuanshengADK = lplatform.uiEngine.createChaping(
                                    t.adList[0],
                                    function () {
                                        e.yuanshengADK = null;
                                    }.bind(e),
                                    function () {
                                        o.reportAdClick({adId: t.adList[0].adId}), (e.yuanshengADK = null);
                                    }.bind(e)
                                ));
                    }.bind(e)
                ),
                o.onError(
                    function (t) {
                        console.log("nativeAd.onError:" + JSON.stringify(t)),
                            o.destroy(),
                            e.yuanshengADK &&
                                e.yuanshengADK.destroy &&
                                (lplatform.plog("onError this.yuanshengADK.destroy:" + e.yuanshengADK.destroy),
                                e.yuanshengADK.destroy());
                    }.bind(this)
                ),
                o.load();
        }),
        (a.onInterstitialLoad = function () {}),
        (a.onInterstitialError = function (e, t) {
            lplatform.plog("onInterstitialError code:" + e + " msg:" + t);
        }),
        (a.onInterstitialClose = function () {}),
        (a.showInterstitial = function () {
            lplatform.labData.useNativeAd ? this.loadInterstitial(!0) : this.loadNativeTemplate(!0);
        }),
        (a.hideInterstitial = function () {}),
        (a.loadNativeTemplate = function (e) {
            if ((void 0 === e && (e = !0), lplatform.cparam.nativeTemplateID)) {
                var t = Math.min(this.info.windowWidth, this.info.windowHeight),
                    o = (9 * t) / 16,
                    n = this.info.windowWidth,
                    i = qg.createCustomAd({
                        adUnitId: lplatform.cparam.nativeTemplateID,
                        style: {top: (this.info.windowHeight - o) / 2, left: 0.5 * n - (0.8 * t) / 2, width: 0.8 * t}
                    });
                (this.customAd = i),
                    e &&
                        i
                            .show()
                            .then(function () {
                                console.log("show success");
                            })
                            .catch(function (e) {
                                console.log("show fail with:" + e.errCode + "," + e.errMsg);
                            });
            }
        }),
        (a.onGameRecordStop = function (t) {
            e.prototype.onGameRecordStop.call(this, t), this.gameRecorderManager.saveToAlbum();
        }),
        (a.shareRecord = function () {}),
        (a.makeShareUI = function (e, t, o, n, i) {
            void 0 === n && (n = 0), void 0 === i && (i = !1), t && t();
        }),
        (a.analytics = function () {}),
        (a.httpRequest = function (e, t, o, n, i) {
            var a = new XMLHttpRequest();
            (a.timeout = o),
                (a.onreadystatechange = function () {
                    4 == a.readyState &&
                        (a.status >= 200 && a.status < 400
                            ? t(null, a.response, a.responseText)
                            : t(a.status, null, null));
                }),
                a.open(n || "GET", e, !0),
                a.send(i);
        }),
        (a.goToGameOrGameList = function () {
            lplatform.plog("Oppo未实现 goToGameOrGameList");
        }),
        n
    );
})(((n = e("PTT")) && n.__esModule ? n : {default: n}).default);
(o.default = a), (t.exports = o.default);
